﻿CREATE PROCEDURE [dbo].[sp_Insert_Agent]
	@Name VARCHAR(50), 
	@Latitude VARCHAR(9),
	@Longitude VARCHAR(9),
	@MdNumber Varchar(4)
AS
	declare @AgentID int

	INSERT INTO [dbo].[Agents]
			   ([Name]
			   ,[Latitude]
			   ,[Longitude]
			   ,[MdNumber]
			   ,[ActiveContacts]
			   ,[ActiveAppointMade]
			   ,[ActiveAppointKept]
			   ,[ActivePresentation]
			   ,[ActiveAppointSale]
			   ,[LapsedContacts]
			   ,[LapsedAppointMade]
			   ,[LapsedAppointKept]
			   ,[LapsedPresentation]
			   ,[LapsedAppointSale]
			   ,[NeighborContacts]
			   ,[NeighborAppointMade]
			   ,[NeighborAppointKept]
			   ,[NeighborPresentation]
			   ,[NeighborAppointSale]
			   ,[BusinessContacts]
			   ,[BusinessAppointMade]
			   ,[BusinessAppointKept]
			   ,[BusinessPresentation]
			   ,[BusinessAppointSale]
			   ,[RefContacts]
			   ,[RefAppointMade]
			   ,[RefAppointKept]
			   ,[RefPresentation]
			   ,[RefAppointSale]
			   ,[TSystemContacts]
			   ,[TSystemAppointMade]
			   ,[TSystemAppointKept]
			   ,[TSystemPresentation]
			   ,[TSystemAppointSale]
			   ,[TargetMarketContacts]
			   ,[TargetMarketAppointMade]
			   ,[TargetMarketAppointKept]
			   ,[TargetMarketPresentation]
			   ,[TargetMarketAppointSale]
			   ,[FieldContacts]
			   ,[FieldAppointMade]
			   ,[FieldAppointKept]
			   ,[FieldPresentation]
			   ,[FieldAppointSale]
			   ,[AvgAPVperApp]
			   ,AgentCode)
		 VALUES
			   (@Name
			   ,@Latitude
			   ,@Longitude
			   ,@MdNumber
			   ,0.9
			   ,0.5
			   ,0.75
			   ,0.6
			   ,0.25
			   ,0.6
			   ,0.4
			   ,0.6
			   ,0.5
			   ,0.25
			   ,0.9
			   ,0.5
			   ,0.6
			   ,0.33
			   ,0.25
			   ,0.7
			   ,0.6
			   ,0.5
			   ,0.33
			   ,0.25
			   ,0.6
			   ,0.5
			   ,0.6
			   ,0.33
			   ,0.25
			   ,0.9
			   ,0.5
			   ,0.6
			   ,0.33
			   ,0.25
			   ,0.75
			   ,0.5
			   ,0.6
			   ,0.33
			   ,0.25
			   ,0.9
			   ,0.5
			   ,0.75
			   ,0.6
			   ,0.25
			   ,475
			   ,CAST(RAND() * 10 as int))

	set @AgentID = @@IDENTITY
	
	update Agents set AgentCode = @AgentID where ID = @AgentID

	GO